package com.mindainfo.groundwave.web.device.web;

import com.mindainfo.groundwave.common.bean.CommonResult;
import com.mindainfo.groundwave.common.bean.ResultFactory;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by MD-01 on 2017/5/18.
 */
@Controller
@RequestMapping("/sys/equipment")
public class EquipmentController {

    @RequestMapping("/page")
    public String page(){
        return "/device/equipment";
    }

    @RequestMapping("/testUrl")
    public String testUrl(){

        return "/device/test";
    }

    @RequestMapping("/testMethod")
    @RequiresPermissions("equip:testMethod")
    public String testMethod(){
        test();
        return "/device/test";
    }

    @RequestMapping("/testUrl2")
    @ResponseBody
    public CommonResult<Void> testUrl2(){
        return ResultFactory.ok();
    }

    @RequestMapping("/testMethod2")
    @ResponseBody
    public CommonResult<Void> testMethod2(){
        test();
        return ResultFactory.ok();
    }

    //@RequiresPermissions("equip:testMethod")
    private void test(){

        Subject currentUser = SecurityUtils.getSubject();
        currentUser.checkPermissions("equipment:testMethod");

        if(currentUser.isPermitted("equipment:abc")){
            System.out.println("有equipment:abc权限");
        }else{
            System.out.println("没有equipment:abc权限");
        }

        System.out.println("访问test方法");
    }
}
